refactor init code