add some boundary check