Implement run_task function