Refactor/typeclasses