Added automatic inventory updating and cleaned code a lot