Moved main io functions out of its own module