Refactored the initialization code