Periodic boundary condition added

Periodic boundary condition added plus some other performance
improvements.