changed js file to be more modular