This code implements this very slick concept. All credits goes to that author.