Add type checking and validation to functions. Add unit tests.