refactoring vector operations for speed