Agent fix

Rebase from #115