merger code from the new leafclient.