Fix Python 3 support

The metaclass syntax changed quite a lot.