Moved I/O code to a library module