Minor formatting changes; some JS bugfixes/optimizations