pull conditionals out of loop