refactoring of js complete