Properly deallocate nodes