Improve message handling.

Resolve #11