Fix flake8 errors and use six.with_metaclass instead of some hack