Fixed bug in NBT saving and added missing close() functions.