Added all the original code

Will slowly, ruthlessly, clean up the code on a separate branch.