Fixed up main slightly for optimization