extract the logic of the counter from the main method