add error handler & fix some stuff