improve and separate out lattice compatibility layer