refactor for threading

no same-line ifs, space after 'if'.