Fix writeRegister and readRegister