Corrected message validation function