Add type checking

And move all functions to a common interface