Refactored initialization code