Refactored all filesystem I/O into a separate .[ch] source file