algorithm edits. Algorithm won't terminate though