refactored from thread to task