more modular code for emscripten WIP [skip ci]