Improved inventory function