updating key logic