edits to algorithm