moved error functionality to err_fn parameter