Implemented part 3 of homework