Added locks. TODO: plotting needs to happen in main thread.
Swapped threads. Fixed lattice.generate logic.