Pulled in the code from Trullo and whipped it into shape.