Major tidying of code

Including new data from Ali.