added reading and writing functions.