added some algo improvements