optimizations and re-formatting