add main function and command line running support