Convert a Fǎnqiè reading to it's MCH counterpart.
    
    Important: we need to identify the medials in the xia-syllable. We also
    need to make additional background-checks, since in the current form, the
    approach is not error-prone and does not what it is supposed to do!

def fanqie2mch(fanqie, debug=False):
    """
    Convert a Fǎnqiè reading to it's MCH counterpart.
    
    Important: we need to identify the medials in the xia-syllable. We also
    need to make additional background-checks, since in the current form, the
    approach is not error-prone and does not what it is supposed to do! 
    """
    
    # check for gbk
    fanqie = gbk2big5(fanqie)
    
    # get normal vals
    shangxia = chars2baxter(fanqie)
   
    # check for good fixed solutions in our dictionary
    if fanqie[0] in _cd.GY['sheng']:
        shang = _cd.GY['sheng'][fanqie[0]]+'a'
    else:
        shang = shangxia[0]

    xia = shangxia[1]

    # check for bad vals
    if ' ' in shang:
        shang = shang[:shang.index(' ')]
    if ' ' in xia:
        xia = xia[:xia.index(' ')]

    if ',' in shang or ',' in xia or not shang or not xia:
        raise ValueError('fanqie {0} {1} is ambiguous'.format(shang,xia))
    
    # parse chars
    shangp = parse_baxter(shang)
    xiap = parse_baxter(xia)
    
    if debug:
        return '.'.join(shangp),'.'.join(xiap),shang,xia
    
    i = shangp[0]
    m = xiap[1]
    f = xiap[2]
    t = xiap[3].replace('P','').replace('R','') # ugly, change later XXX
    
    # clean medial-relations
    if ('y' in i or 'i' in f) and 'j' in m:
        m = m.replace('j','')
    if 'u' in f and 'w' in m:
        m = m.replace('w','')
        
    return ''.join([i,m,f,t])