logic optimize