fixes major bug in algorithm