refactored some of inventory code.

It's not finished, but it's now far easier to understrand.

At some point in future it will be factored again, and I will probably
add custom property editor specific to inventory. (that's why it will
require another refactor, but far smaller than the one going on now)