minor changes, making code close to java version