Improved subclassing

Replaced fix class type through instancetype and used self in static methods instead of fixed class reference to enable improved subclassing.
This will break compatiblity with older compilers, but if needed we could define a macro to use either id or instancetype.