Read and write functions seem to work perfectly now