Added a function to check whether key exists.