Fixed bug in main.pl that caused dramatic inefficiency.