MNT : more input sanitization
MNT : simplified type guessing code