[minor] Reduce duplicate code