Some formatting and commenting, plus more error handling for events