ported to javascript