Refactoring of js