Finalized vectorizing code