Cleaning up and writing proper page functions