Tidied up code, as agreed in Janelia