refactoring, removed 60% of C++ code in favor of JS