fix makefile and add handle_error function