anchor.diff:  			end;
   		StreamId ->
   			NrValues = case wrq:get_qs_value("nr_values",ReqData) of
  -						   undefined ->
  -							   50;
  -						   Values ->
  -							   {Value,_} = string:to_integer(Values),
  -							   Value 
  -					   end,
  +								   undefined ->
  +									   50;
  +								   Values ->
  +									   {Value,_} = string:to_integer(Values),
  +									   if 
  +										   Value > 500 ->
  +											   500;
  +										   Value < 3 ->
  +											   3;
  +										   true ->
  +											   Value 
  +									   end
  +							   end,
   			NrPredictions = case wrq:get_qs_value("nr_preds",ReqData) of
   								undefined ->
   									"25";
   								Predictions ->
  -									Predictions
  +									{Preds,_} = string:to_integer(Predictions),
  +									if 
  +										Preds > 500 ->
  +											"500";
  +										Preds < 1 ->
  +											"1";
  +										true ->
  +											Predictions 
  +									end
  +							
   							end,
   			case erlastic_search:search_limit(?INDEX, "datapoint","stream_id:" ++ StreamId ++ "&sort=timestamp:desc", NrValues) of
   				%case erlastic_search:search_json(#erls_params{}, ?INDEX, "datapoint", create_json(StreamId), []) of
  
positive.code: %% @end
  -spec forecast(JSON::string()) -> JSON::string().
  forecast(Json) ->
          forecast(Json, 25).
  
  %% @doc
  %% Function: forecast/2
  
negative.code: %% @end        
  -spec format_result({Mean::list(), Lo80::list(), Hi80::list(), Lo95::list(), Hi95::list()}) -> string().
  format_result({[HeadMean|[]], [HeadLo80|[]], [HeadHi80|[]],[HeadLo95|[]], [HeadHi95|[]]}) ->
  	"{ \"value\":" ++ lists:flatten(io_lib:format("~p", [HeadMean])) ++
  		",\"lo80\":" ++ lists:flatten(io_lib:format("~p", [HeadLo80])) ++
  		",\"hi80\":" ++ lists:flatten(io_lib:format("~p", [HeadHi80])) ++
  		",\"lo95\":" ++ lists:flatten(io_lib:format("~p", [HeadLo95])) ++
  		",\"hi95\":" ++ lists:flatten(io_lib:format("~p", [HeadHi95])) ++ "}]}";
  format_result({[HeadMean|Mean], [HeadLo80|Lo80], [HeadHi80|Hi80],[HeadLo95|Lo95], [HeadHi95|Hi95]}) ->
  	"{ \"value\":" ++ lists:flatten(io_lib:format("~p", [HeadMean])) ++
  		",\"lo80\":" ++ lists:flatten(io_lib:format("~p", [HeadLo80])) ++
  		",\"hi80\":" ++ lists:flatten(io_lib:format("~p", [HeadHi80])) ++
  		",\"lo95\":" ++ lists:flatten(io_lib:format("~p", [HeadLo95])) ++
  		",\"hi95\":" ++ lists:flatten(io_lib:format("~p", [HeadHi95])) ++ "},"
  		++ format_result({Mean, Lo80, Hi80, Lo95, Hi95}).
  
  
  %% @doc
  