better error handling; new agent and statement tests