Refactor to single thread