Port new code to Python 3 as well, fix six.with_metaclass() issues

Many thanks to @atheiste for the big porting steps!