key function working properly