Cleaned up some code. Now save results to file