Patch for #312 and #301