Added error handler and logs