rebase the patches for bugs 587757 and 808370. address review comment for bug 808370. new patch for bug 859170 - need to add a test