save, read and write functions implemented by Pucong:)