Handle boundary conditions too.