added some type checking