ported to java script