Implements periodic boundary conditions

Amit's contribution for periodic boundary code