Improved message handling. Less hackish now.