Refactored trip separator into smaller functions