Memory leak fix

Node and Item creation now only happen when necessary.