first pass at refactoring the relay/bridge logic, significant cleanup