Finish writing function