Refactored some code. Added validation.js to check for pages