Bug fix: ensure client is defined before we use it