refactored out function from typeclass