Rework lattice implementation to improve performance