Fix bug in key counting.