Add precount loop to trail

Add precount variable outside "for" loop for trail variable