Move method body optimization and emit code into a separate class.