refactoring code js homepage