improved read-write code and comments