First attempt at solving Problem 2-3. Doesn't track scopes properly.