Made keyboard logic more readable