relay: fix multiple bugs