Added saving results. Improved code.