Remove code duplication.
Add counting metric.
Remove useless file, remove bug in test.