Updated KeypadScan function