Change order in if test for better performance.