tidied up and tested on new platform