events: add ref counter to observers

The same observer is only allowed to execute once, but it's possible
that it can be added multiple times. The ref counter makes sure the
observer is only removed after all references are removed.