This cost much more than everything in this function, perhaps just a `for ()` loop?