Working Implementation 2

Works better than the previous implementation. I don't think there's anything else to do other than to add comments onto my code which I haven't done.