Corrected algorithm - scored 7 on all tasks