modularize the js further