added sudocode for relay