moved code around so main is above everything else