Handling boundary conditions