Homework Assignment 1, task 3, now working, slightly hacky fix and would like to know a better way to implement this.