Fixed some bugs with reading and writing