calculate count correctly