Fixes from Petr on rebased PR 422
Merge pull request #423 from hflynn/agent_fix

Fixes from Petr