Typeclasses

Existing code was refactored in order to define Typeclasses in a more generic way.