Modularized the javascript code