HUGE changes

This is a more up-to-date version of the main file, with lots of stuff
added to handle different kinds of scans. It also fixes bugs with
stopping the scan threads.

THIS MIGHT BREAK THINGS!!!!
Hopefully not. I am 75% sure it won't break anything.