fixed issue #12 but differently from pull request #15