Fixes crash when closing view