rearranging switchcase analysis code into different functions.  UGLY but
broken up and working.  prettification to follow.