How to check for boundary conditions