push the ifs up and the fors down
doing so makes branching logic easier to follow and test. it also has a large performance impact as only happen once.
doing so makes branching logic easier to follow and test. it also has a large performance impact as only happen once.