Refactoring of JavaScript COde