fixed keyerror bugs