Split up the optimizer code #247