Refactor serve page code; show not found when database empty and url not homepage.