Tidied mti20's contributions so code is ready for submission.