Make ajax pagination more robust