Separating input and output handling to make it easier to write multiple files