various cleanups, fixes and major documentation rewrite of the text module