Fixing write/read functionality