Added reading and writing functions.