Complete function to create pages. Added the ability to edit pages