refactor and get ready for offline compressing

I think this will break, I cant see where filename is initialized.