Remove even more C++
Port C++ code to JS
change factory signature