Added basic type checking and error handling.