added latest code for Stu to look at, no idea if tests even pass