slight improvement to smart_truncate functino