Added StateStack to track state between context shifts