You need to store these on a stack rather than having them apply globally. Otherwise, you'll miss functions within functions.