move gen filling to a function