Refactored code to remove duplicates and to allow a separate layout just for the homepage.