Fix string truncation function