various type checking and overflow checking

various type checking and overflow checking