add new functions and fixed read and write functions