changes to work with tsv whitelist; file closing implemented