Fixed some bugs and added lattice boilerplates.