40c bed temp is too cold.
for pla - 65c is optimal.
85c for abs
and 100-110c for pet-g

It's essentially the glass point of the material.
ie: that temp where it's still everso slightly flexible and hasn't cooled enough to shrink.
You need it hard - if it's too soft it'll collapse/squish and ruin subsequent layers.

If it's stringing excessively then you're printing too cool and - probably - your retraction settings are wrong.

I find that pla printss best betwen 200-215c - depending on speed, layer thickness and cooling duct efficiency.

Pet-g, hell I've seen everything from 220c on up to 255c - seems to depend entirely on who made it and who's using it. So trial and error there.

Abs - again I've seen everything from 220c on up to 260c. And again seems to depend on make, colour and whether or not you have a heated enclosure. The better the heated enclosure the higher you can get away with printing it. And the better your layer adhesion will be.