refactored vector-checking code