Partially rewrote inventory code.