Minor refactoring, fixes for emscripted apps