Refactor tx to file.

This will make writing rx easier.