Added events, improved state handling