Adjusted the compact optiization function.