First file of cleaned up optimizer code