ported from Java version.