refactor some tasks and add some error handling in tasks