Implement counters. Fix issues. Refactor code and tests