Algorithm works. Now to clean up and save.