extract client builder
refactor using try with resources