Add code for #564 as a new branch

After a lot of messing about with git I finally managed to cleanup my mess.
Now it's a single commit.