fitting and limit scripts improved and debugged