Refactor initialization code