small fixes to algorithm