use counter instead of naive recursive function

Signed-off-by: Andrew Tselischev <andrewtselischev@gmail.com>
Looks like this works!

- B (2012-11-01): Теги

Signed-off-by: Andrew Tselischev <andrewtselischev@gmail.com>
cleanup

Signed-off-by: Andrew Tselischev <andrewtselischev@gmail.com>
Merge branch 'master' of github.com:andrewts/Coding