One additional comment. All the code within each of your "when" blocks of the case statement could be taken out and put into a method. That way the case statement would be made up of a bunch of method calls. It makes the code neater. :)
when "1"
  call_method_1()
when "2"
  call_method_2()