moved truncate function to appropriate place