Add current version of optimization script (still a bit messy)