Re-write inventory_market_helper, fixes #304

Thanks Sharkiller for the initial idea!