refactor counter