Fix for #348
Added patch for #316.