cleaned up optimizer code