Improving thread detection code.
INCOMPLETE: Working on color coding convention; later possibly followed by clustering too.