version where primitive counting function works

without elegant cookie solution.