Break down main function; capitalize global vars