Improve inventory sorting functions