cleaned up Mathematica script