Rewrite main program and add command arg support.
Update and fixes for CMake script.