Some messy Mathematica code.