refactor for threading

Please follow existing standards when coding.

This includes for adding documentation.

In particular:
1. It goes in headers
2. It uses the @command notation rather than \command notation.
3. It uses the style:
/** For multiline doxygen docs.
 * The document goes here. Not no tabs between * and text, just a space.
 * See /all the existing code/ for more examples.
 */
or 
/// For one or two liners,
/// just use three slashes.