added relay debugging and smarter relay stuffs