Massive cleanup/restructuring of code (still not using config files, though).