refactored the js file to oo design