changed interface so we need to pass in a func to do the output formatting and writing