on/off event registration and less looping

This implements suggestions in #1, #3 and #4.
It wasn't possible to separate them in different PR's.

This is obviously a suggestion. Feedback much appreciated.