Added functionality for keeping track of loops.