Corrected keyboard logic