moved the except KeyError to a position where it actually functions