Renamed StateStack to StackedState and clean up code