These huge bocks of code should REALLY be a function, but we can't be bothered right now