Refactor code to remove array allocation.