refactor count