modify internal codes to use stream apis.