functional optimization script using the modified step 1