Splits js into two files
Fixes some unintentional global vars