Added support for Registering Agents and lots of little refactorings