refactoring code for the tasks