add support for multiple threads and persistent connection.