Added tests and working error handler