Tidied version of #566

#566