Refactored into separate libraries and added hook for external message handlers