Changed to work with CMPS10 (and tidied a bit)