Adding error trap for KeyError