Rewrite with zero used memory and reduced allocations in mind