Finished the backend of reordering the pages