Refactor most of C++ and js code. Add missing semicolons.