Rewrite in/out file handling

Signed-off-by: Michael Buesch <m@bues.ch>