Cleaned flags, rewrote lsd, better invgen.