Fixed bug in optimizer with named registrations. Moved some stuff.