Fixed the event managing system

Fixed the event managing architecture; upgraded to work with functions
instead of objects, and upgraded to make sure it properly registers the
listeners.