refactor. use type classes for functions.