preliminary function taking periodic boundary conditions into account was added