fixed bug in counting, boxes were handled incorrectly