Added code for task IV.