fixed some bugs, agent runs more logically