Detach children on button press

I'm writing some code to enable you tomove object in the environment around using a tracked object with a camera. I have some code here which makes an object in front of my 'controller' become a child of the controller in order to freely move it around, and it works great. However, I also want to be able to drop the object back upon another button press, and I'm evidently doing something wrong. When I add this code, it makes the whole thing not work. I'm not sure why - maybe it's something to do with both pieces of code being in the Update function?

function Update () {
var fwd = transform.TransformDirection (Vector3.forward);
//Defining the travel direction of the raycast vector
var hit :  RaycastHit;
//If Raycast collides with something, hit = true?
var LayerMask = 1 << 9;
//Interacts with 1 layer - Layer 9 - Moveable

var hasObject = false;

//Draws ray vector in Scene view
Debug.DrawRay(transform.position, fwd * 50, Color.green);

//if Raycast finds a collider in front of this object in layer 9, print message 1, else print message 2.
    if (Physics.Raycast (transform.position, fwd, hit, 50, LayerMask)) {
        print ("There is something in front of the object!");   
        if (Input.GetButton ("Fire2") && (!hasObject)) {
        hasObject = true;
        var otherThing = hit.transform; 
         otherThing.rigidbody.isKinematic = true;   
         }  
        otherThing.parent = transform;

    }
        **********************************************************************
            if (Input.GetButton ("Fire2") && (hasObject)){
        transform.DetachChildren();
        otherThing.rigidbody.isKinematic = false;
        hasObject = false;}
        else print ("Nothing in front of the object!");
            **********************************************************************

So the variable hasObject is meant to decipher whether an object has already been picked up by the controller or not. If an object is already attached, it's meant to detach it and make its rigidbody active again. If I disable the whole section of code between the lines of asterisks, the object parenting code works fine, but if its enabled, it doesn't. Anyone having any ideas what I'm doing wrong?

The problem is having 2 separate if watching the same condition. Also I feel like the general order of things is somewhat confused. I'd go like this:

var hasObject:boolean;
var otherThing:Transform;

if(Input.GetButton("Fire2")){
    if(hasObject){
        otherThing.rigidbody.isKinematic = false;
        otherThing.parent = null;
        hasObject = false;
        print("Dropped "+otherThing.gameObject.name+"
");
    }else{
        if(Physics.Raycast(transform.position, fwd, hit, 50, LayerMask)){
            otherThing = hit.transform; 
            otherThing.rigidbody.isKinematic = true;   
            otherThing.parent = transform;
            hasObject = true;
            print("Picked up "+otherThing.gameObject.name+"
");
        }else{
            print("Nothing to pickup!
");
        }
    }
}

EDIT: Corrected, not tested. Assuming a single click to pickup and next click to release.