Added command line support and refactored.