Fixes for crashes on close