fixed logic around bad codes