code refactoring of JS side