Code for my thesis. Currently very messy so feel free to email me at [email protected] if you wish to use/understand it