Fixed check for existing keys