split off Lattice and improve the rest of the code