threadsafe, refactor