refactors to remove unnecessary check
refactors to make large if block slightly clearer in intent