some optimizations in repair model generator