several instances of if type(variable == something) should be if type(variable) == something
several instances of
if type(variable == something)
should be
if type(variable) == something