Fixing algorithm. Making progress.