improved message handler