improve union-find structure compression. Also include several small code simplifications