Copied in Mislove's code