Refactoring: cancel multithreading and clean up the API.