Issue #783: python3 compatible - sort types by name since they are unorderable in 3.x.
Issue #783: python3 compatible - use explicit floor division (// instead of /).
Issue #783: python3 compatible - use explicit inplace floor division (//= instead of /=).