Second pass at vectorising the loops