Move cheap checks earlier to avoid more expensive ones