use the with statement around track_element generator. this ensures that files are closed, even though StopIteration isn't reached.