Refactored triplets processing.