addded some type checking