COSMIT refactor Hungarian algorithm