Optimize some if then