Corrected handling of typeerror