added code to fix the key error.