Fix count bug that was caused by order statements