replaced last loop with stream