Refactor clientEvents logic