Move cheap checks earlier to avoid more expensive ones
Merge pull request #412 from Dmitry-Me/moveChecksEarlier

Move cheap checks earlier to avoid more expensive ones