fixed the counting function to be better