Use Task instead of Thread in various places