broke out into functions, implemented the (stupid) single return rule, (seriously, see how many nested if's it generates.), and added timestamps to logfile.