Adds proper file handling for input and output