Added events and changed state system slightly.