Task 3 codes (almost) finished