added boundaryCheck