made eeprom write procedure more robust