patch from victzhang to fix issue #25