merge code to flax lib