reworks generation process (code still ugly tho)