fixed bugs in periodic boundary