Updated key algorithm