Fix for #323 and #322