Added some new functions to handle ajax pagination and main queries