add command line editing and history

also, some refactoring to de-bulk main()