dn - Added waiting for cli jobs to finish and other refactoring