add err_handler and util functions