Tidied up version for sending to Jim Stone