refactored addtasktolist code