moved State completely into implementation and improved code readability by adding a State::flush()