Improve handling of typeclasses