Filled in a lot of missing pieces. It runs now, but I think it is safe to assume it doesn't actually work.