JC-1591 Javascript refactoring