fix error checking
write to filename (#3)
write to callback (broken)
doco