Refactor init method logic extract codes to functions