Improve API for defining events