use stream instead of imprative for-loop