Translated Hungarian algorithm for a better heuristic for marginal performance gains and a whole file of ugly imperative code