fix for running unit tests in py versions < 3
fix for running unit tests in py versions < 3
Change exception catch order in the receiver loop, and remove the outermost exception handler (which was unnecessary). Also general tidy up of code