Fixed boundary conditions and made it faster