Fix compare methods and use type_code in __cmp__

Wouldn't  it be a better idea to use `auto` here? It will be more maintainable.