State management.

Added state stack.