replace loops with streams