Slightly refactoring of kex handler