checkAndUnion optimization and bugfix