Add function for I/O handling