added code taken from Arm SD card. This ought to be final changes. Will be renaming branch to final?