adding error handler and tests