Added hooks for events (still needs to be debugged!)