Check whether data is non-null and contains msg

This should hopefully stop it blowing up when the message is null or incorrect.