optimized text function