some refactorings to homepage.js

clean up the code and remove some duplications