Got rid of copy-paste in gen_counter. Now using anonymous functions.