changing the js structure drastically. halfway done and all the functionalities are working.