It looks like there might be an issue with how you're using the ifThenElse function. The logic seems inverted. Try reversing the outputs:
plaintext...