Refactor homepage code

Homepage generation code made cleaner and more automated