add test and fixed bug on key creation