added optional callback to specify own file saving mechanism