Fixing issue #392, adding tests.