fixed check for existing keys