[swt.m]: turn swt into a function, add connected component code