simplified several checks by refactoring