refactoring init logic