fixed the bug for the function next_page