Optimize function condition