Added card type detection unsing ATR. Added logging and fixed resource leaks