refactoring; better events; better errors