Fix algorithmn

Some variables had their names from the code from which this was ported. Fixed that.