added proper error handler