moving most of the code into individual functions.

intial framework put in place but will require lots of testing.

diff --git a/controller/usercontrol.rb b/controller/usercontrol.rb
index bd22be4..f1d6ba4 100644
--- a/controller/usercontrol.rb
+++ b/controller/usercontrol.rb
@@ -1,32 +1,42 @@
 tcvolume = "~/Dropbox/newdropbox"
 cfnpath = "/opt/aws-cloudformatino-tools/"

-puts "Mount true crypt volume? (y/n)"
-answer = gets.downcase.strip
-if answer == "y"
-  puts "Mounting #{tcvolume}"
-  result = %x["truecrypt #{tcvolume}"]
-elsif answer == "n"
+def mounttc(tcvolume)
+  puts "Mount true crypt volume? (y/n)"
+  answer = gets.downcase.strip
+  if answer == "y"
+    puts "Mounting #{tcvolume}"
+    result = %x["truecrypt #{tcvolume}"]
+  elsif answer == "n"
     puts "Not mounting tc volume, continuing..."
-else
-  puts "Invalid entry, please use y or n, exiting"
-  exit
+    result = "notmounted"
+  else
+    puts "Invalid entry, please use y or n, exiting"
+    exit
+  end
+  return result
 end

-puts "Checking for existing stack"
-result = %x[/opt/aws-cloudformation-tools/bin/cfn-describe-stacks "setec-astronomy --show-long"]
-if result.include?("not set")
-  puts "Please run usercontrol.sh, environmental variables not set"
-elsif result.include?("stack")
-  existingstack = result.split(",")[1]
-  puts "Stack found, #{existingstack}"
-  hasstack = true
-elsif result.include?("Malformed")
-  puts "Network connectivity issue, please ensure you have internet access, exiting"
-  exit
+def check4stack()
+  puts "Checking for existing stack"
+  result = %x[/opt/aws-cloudformation-tools/bin/cfn-describe-stacks "setec-astronomy --show-long"]
+  if result.include?("not set")
+    puts "Please run usercontrol.sh, environmental variables not set"
+  elsif result.include?("stack")
+    existingstack = result.split(",")[1]
+    puts "Stack found, #{existingstack}"
+    hasstack = true
+  elsif result.include?("Malformed")
+    puts "Network connectivity issue, please ensure you have internet access, exiting"
+    exit
+  else
+    puts "Stack not found"
+    hasstack = false
+  end
+  return hasstack
 end

-if hasstack
+def killstack()
   puts "Would you like to kill your existing stack? (y/n)"
   answer = gets.downcase.strip
   if answer == "y"
@@ -38,30 +48,52 @@ if hasstack
     puts "Invalid entry, please use y or n, exiting"
     exit
   end
+  return result
 end

-puts "Would you like to create a new stack? (y/n)"
-if answer == "y"
-  result = %x[/opt/aws-cloudformation-tools/bin./cfn-create-stacksetec-astronomy "--template-file ~/src/setec-astronomy/aws/setec-astronomy.template --parameters=KeyName=setec-astronomy"]
-elsif answer == "n"
-  puts "Exiting"
-  exit
-else
-  puts "Invalid entry, please use y or n, exiting"
-  exit
+def createstack()
+  puts "Would you like to create a new stack? (y/n)"
+  if answer == "y"
+    result = %x[/opt/aws-cloudformation-tools/bin./cfn-create-stacksetec-astronomy "--template-file ~/src/setec-astronomy/aws/setec-astronomy.template --parameters=KeyName=setec-astronomy"]
+  elsif answer == "n"
+    puts "Exiting"
+    exit
+  else
+    puts "Invalid entry, please use y or n, exiting"
+    exit
+  end
+  return result
 end

-puts "Waiting for stack ip to be populated..."
-puts "Checking"
-result = %x[/opt/aws-cloudformation-tools/bin/cfn-describe-stacks "setec-astronomy --show-long"]
-if result.include?("not set")
-  puts "Please run usercontrol.sh, environmental variables not set"
-elsif result.include?("stack")
-  existingstack = result.split(",")[1]
-  puts "Stack found, #{existingstack}"
-  hasstack = true
-elsif result.include?("Malformed")
-  puts "Network connectivity issue, please ensure you have internet access, exiting"
-  exit
+def verifystack()
+  puts "Checking"
+  result = %x[/opt/aws-cloudformation-tools/bin/cfn-describe-stacks "setec-astronomy --show-long"]
+  if result.include?("not set")
+    puts "Please run usercontrol.sh, environmental variables not set"
+    return "error #{result}"
+  elsif result.include?("stack")
+    existingstack = result.split(",")[1]
+    puts "Stack found, #{existingstack}"
+    hasstack = true
+    return existingstack
+  elsif result.include?("Malformed")
+    puts "Network connectivity issue, please ensure you have internet access, exiting"
+    return "error #{result}"
+    exit
+  end
 end

+mounttc(tcvolume)
+hasstack = check4stack()
+if hasstack
+  killstack()
+end
+createstack()
+puts "Waiting 15seconds for stack ip to be populated..."
+sleep 15
+newstackip = verifystack()
+if newstackip.include?("error")
+  puts "error verifying new instance, #{newstackip}"
+else
+  puts "new stack ip is #{newstackip}"
+end