Fully working version.
Possible extensions: different msg types