starting on counter taking algorithm