switched to getopt for better portability