Fix compare methods and use type_code in __cmp__