Refactor main js of index page