add more condition to check boundary