code and test for issue 39