added better KeyError handling