Added tests to error handler & refactored.