Fixed issue #17. Thanks to Sergey Vinogradov for bug report.