fixing optimize method