Moved file io into a separate file to simplify