Looped task 3 and put operations into functions