improved TextDetection code