I've just merged in this and the following fix from @ajohnstone expecting the changes were OK