fixed counting errors