Tidied up some of the doublematrix code