Fix bug calculating limit in selectBy