Small refactoring for pagination code
Move a def closer to where it's used
Only display autocomplete suggestions if the query hasn't changed