added more type checking safety