Changed comparison between monitoringTasks and Agents

Fixed comparison between monitoringTasks and agents. Note - will not work with more than one agent!