fixed oversight in algorithm