Cleaned up helper functions.
Moved $rootScope.$apply to core message handling.