Test & proposed fix for GH #40

Cherry pick 89a66c9 to see the test failures, and 229d061 to see them pass. See #40 for issue & stacktrace.