Lots of changes to get relaying working and to improve tests #302