Cleaning up inventory.php

Moved common functionality out into helper files.
Improved variable names.