Fixed pagination and improved functions