refactor for threading

Coding standards (space after if)