Optimize some code for text overlays

Optimize some code for text overlays