refactored command line code into C extension module for python