count zeroes function with abstraction