fixing algorithm