Improved the initial checks and made it easier to read