I don't think this is very efficient, this method would have pretty high allocations. Might be worth optimising later