Cleaner code, and dispose thread if needed