fussing with error pages, refactored code to better locations