General clean up and improvements in cfg_agent code

Change-Id: I4c5bae12172149b1f39ab99771b1ef4bb51d207f