How do I stop reading of detail file after a certain threshold is reached