relay: much more refactoring and moving classes