Refactored message processing