Optimizations and reformatting