A very messy piece of code I did for university.