add inventory functions, some improvments and fixes