Added a first draft (it needs fixing) of the io code