Radically refactored code, implements test protocol 1.2b