Refactored test stream code for the whole protocol