Fixed crash at program exit