finalize function to write our results