work on refactoring agent code