Updated working code with EEPROM