Fix bug when reading and writing values