Part 1 in working condition, still needs to be cleaned up and commented.
Assumes that the files are mixed up.