refactoring of js file