vec: reduce some code duplication