some changes to reduce memory usage

- filters now filter lines before they're returned
- delete the lines variable after we've extracted what we need