Fixes issue 518

Test and fix for issue 518.