fix a bug of walk across the top and left boundaries