refactor for threading

Guard needed on m_run (this function isn't threadsafe otherwise).