translated last bit of native code from Go to JS (finally!!!)