notes on where we got the smart truncate algorithm from