Optimization overhaul: Less redraw, better organization, bug fixes