Fix for issue #40 #67 and #79