beginig of counter code