Bunch of work on porting over the old code.

Most everything's done at this point aside from actually testing it.