Refactored C++ and JS code.