moved client creation to the end