refactor initialization code to be more async-friendly