refactor for threading

no same-line ifs.