refactor init logic