Fix broken truncate function