start refactoring message handling