massive rewrite of io library