More or less working general fitting routine