refactoring, convert to getopt long