Re-adding fix for issue #40 into develop branch after merge of code from issue #33