Refactore edit and new pages and add tests