Cleanup optimize's nested if statements