This isn't very efficient so needs working on at some point but will do for now