More work on JS refactor.
Small fixes from frosted