upgraded solution applying streams