Fixed memory problem with custom agent
GitHub issue #5