Full implementation of task set 4