added fix by F.D. for periodic boundaries