Cleaning up during state transitions