add two methods checkBoundary() and checkEmpty() to reuse some code