Homepage js, refactor

Refactored js for homepage