Add identification to each cmd's transaction. Fix memory leak. Refactoring code.