Error pages cleanup

Adding some comments and cleaning up the code.