Add error page, move logic from homepage, refactoring