fix variable name next -> done
add options parameter for supporting custom error handlers