Some bug fixes on agents