fixed all known inventory bugs and did some cleaning of the code