Change some of the error code. Fix a bug in template::insertMessage.