Misc performance improvements + Code reformatting