modify source code to work for emscripten