Bug fix, consolidate some initialization code