Refactor import, safely end all threads on close.