Some code improvement and add tests for pages. Because why not.