Fix memory leak in WormholeMessagePublisher and refactor