moved scripts to head and made a javascript more readable