changed formatting, rearranged initial checks to remove redundancy