Updated c# script with changes from the js script (see last commit about Mike)