Convert to Gem

Make all changes to convert the command line code to run as a gem.