handling states with a std::stack