some error checking and type checking