refactor for threading

Pass in shared_ptr as const& to avoid needless copy.