fix broken JS impl