Adding more general fit() function with choice of error functions.