Rewrite messaged in python

This implementation is much simpler and does the exact same thing.