def clean_catalog(wfau_catalog, clean_band='K_1', badclass=-9999,
    maxerrbits=41, minerrbits=0, maxpperrbits=60):
    """
    Attempt to remove 'bad' entries in a catalog.

    Parameters
    ----------
    wfau_catalog : `~astropy.io.fits.BinTableHDU`
        A FITS binary table instance from the WFAU survey.
    clean_band : ``'K_1'``, ``'K_2'``, ``'J'``, ``'H'``
        The band to use for bad photometry flagging.
    badclass : int
        Class to exclude.
    minerrbits : int
    maxerrbits : int
        Inside this range is the accepted number of error bits.
    maxpperrbits : int
        Exclude this type of error bit.

    Examples
    --------
    """
    band = clean_band
    mask = (wfau_catalog[band + 'ERRBITS'] <= maxerrbits) * (wfau_catalog[
        band + 'ERRBITS'] >= minerrbits) * ((wfau_catalog['PRIORSEC'] ==
        wfau_catalog['FRAMESETID']) + (wfau_catalog['PRIORSEC'] == 0)) * (
        wfau_catalog[band + 'PPERRBITS'] < maxpperrbits)
    if band + 'CLASS' in wfau_catalog.colnames:
        mask *= wfau_catalog[band + 'CLASS'] != badclass
    elif 'mergedClass' in wfau_catalog.colnames:
        mask *= wfau_catalog['mergedClass'] != badclass
    return wfau_catalog.data[mask]
