refactor for threading

no single-line ifs.