refactor count()