Fixed a bug involving the periodic boundary conditions