Used Stream API instead of foreach in some places.