Why are you checking this only on the last key?