Reviewed patch for bug 1028407