-major code cleanup in model optimization routines