Improved InsertText function