Solves exercise: Count function extracted to service