transferred from Java to Javascript