Refactored add_key function of Index class.