fixed bug in obtaining key