Fix smartcard related bugs.