Revert "Revert "~ fixed writing/reading bug""

This reverts commit f378d9f787c4a3c9fdec62f8b5d8b2d96f44cf5b.