Refactoring client setTimeout