Refactor to use file handles.