refactoring of js, removing errors