Can you remove some of the allocations in this function using `project` and `unproject`?