General code overhaul and restructuring. I think it runs faster now.