Fixes to the TR optimizer