Work on #590.
Add unit test for #590
Closes #590.
Add test for #509