main js refactor