upstream version as-is from Jason Burks