fixed some errors and pbc