refactored the main js