Cleaning up and updating the code that was actually used.