organized the javascript code