Fix for issue #39 and #40