modified to toggle txt writting