Fixed several bugs. Read and write now reliable