fix for issue #124. Seems to work ok.