Mike Daley #1365 Added tests and extracted smaller classes