fix for crash when truncating twice; code cleanup