Refactored relay handling, testcases are not ok though, still need some
work to be done there.