Fix for #307. Merged from master.