Added custom error pages and made code tidy