More JavaScript refactoring improvements