refactor assimilation code