Add comments to MessageHandler, fixed a few bugs.