Refactored initialization logic