fix bug in handling of rouding errors