Refactored homepage.js code