added more type checking