works with vector instead of mat