rewrite using getopts