text: move I/O related code to separate file