Logging and improved message processing

Still doesn't work.