significant updates to fit script and function, few bug fixes