Added I-O functions.  Worked out some bugs