Midstate optimization