putting destructor in the correct place