added support for command line invocation and added some unit tests