Major redesign using typeclasses