added functionality for terminating main loop from an event. Added template specialization for easy static casting when retrieving a dependency.