Init function refactoring