reorganized the javascript to make it sexier