Fixed error handling for unexpected messages