Refactored the use of client before things got out of hand