some refactoring, added basic agent communication