I'm sure there's a better way of doing this but I cannot remember how I did this ages ago in a better way