Set Flags and Optimize