more refactoring for vectorization