Added OPTIND localization to all functions... which I should have done all along.