Fix for #318. Merged from 3.2.x branch