check NULL before cleaning up