Fixed pagination bug that was producing incorrect results