Fixed bugs in boundary conditions