refactor initialization code