refactored to agent based