Clean up pages.py and add tests.py