Cleaned up state handling.