Fixed bugs in the state stack architecture (includes usage demo)