Changed exception to handle to KeyError