Updated the database connection and some parts of insert agent.