Api events

Mainly the original PR with CF's latest changes.