Improved inventory handling when inventory does not yet exist

Fixes #8324
Improves #7667