reintroduced exit statement in pseudo-algorithm
machine-generated version