Event system

Implemented (untested) event system. #2