shifted event and state code into separate controller