Port fix for #139 to master