Reorganized main.rs, got a bunch of junk out of main and into relevant functions.