fixed truncate function