I think the order of the conditions should be reversed - check the easiest first, and only then the less easy ones.