Various JavaScript fixes (now passes jslint)