Cleaned up logic of page flow, put in validation code in much cleaner
way and documented it with comments.