Implemented basic counting algorithm.