fixed minor bug in getopt implementation.  Moved the for loop out of the while loop.