Cleaned-up code, and added a nicer error page.