Fixed crash at exiting program