Refactored the velocity match code