rewrite with optparse