Added original msg to message handlers.
Fixed bug in gate function.