Optimizing function with vector reassignments

See also: